﻿using Microsoft.Extensions.Configuration;

namespace ProxyServer.AliDns
{
    public static class ServiceCollectionExtensions
    {
        public static IServiceCollection AddAlibabaCloud(this IServiceCollection services)
        {
            services.AddScoped<AliDnsChallengeProvider>();
            services.AddSingleton<AlibabaCloud.SDK.Alidns20150109.Client>(sp =>
            {
                var section = sp.GetService<IConfiguration>()?.GetSection("AlibabaCloud");

                var config = new AlibabaCloud.OpenApiClient.Models.Config();

                section?.Bind(config);

                return new AlibabaCloud.SDK.Alidns20150109.Client(config);
            });

            return services;
        }
    }
}
